/**
 * 
 */
package com.dianwoba.core.jackson;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * @author Zhu
 * @date 2015-12-27 下午2:33:48
 * @description
 */
public class BooleanSerialize extends JsonSerializer<Boolean> {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.fasterxml.jackson.databind.JsonSerializer#serialize(java.lang.Object,
	 * com.fasterxml.jackson.core.JsonGenerator,
	 * com.fasterxml.jackson.databind.SerializerProvider)
	 */
	@Override
	public void serialize(Boolean value, JsonGenerator gen,
			SerializerProvider serializers) throws IOException,
			JsonProcessingException {
		if (value == null) {
			serializers.defaultSerializeNull(gen);
			return;
		}
		if (value) {
			gen.writeNumber(1);
		} else {
			gen.writeNumber(0);
		}
	}

}
